package main

import (
	"github.com/gin-contrib/pprof"
	"github.com/gin-gonic/gin"
	"go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin"
	"go.opentelemetry.io/otel"
	"go.opentelemetry.io/otel/propagation"
	"log"
	"net/http"
	_ "test.com/project-api/api"
	"test.com/project-api/api/midd"
	"test.com/project-api/config"
	"test.com/project-api/router"
	"test.com/project-api/tracing"
	srv "test.com/project-common"
)

func main() {
	r := gin.Default()
	//集成jaeger
	tp, tpErr := tracing.JaegerTraceProvider()
	if tpErr != nil {
		log.Fatal(tpErr)
	}
	otel.SetTracerProvider(tp)
	otel.SetTextMapPropagator(propagation.NewCompositeTextMapPropagator(propagation.TraceContext{}, propagation.Baggage{}))
	//添加接口测速中间件
	r.Use(midd.RequestLog())
	//与tracing里面的服务保持一致
	r.Use(otelgin.Middleware("project-api"))
	//将服务器上的某个文件夹（在这里是/upload文件夹）映射到HTTP路由路径/upload上
	//访问http://your-server/upload/filename.ext就可以看到图片
	r.StaticFS("/upload", http.Dir("upload"))
	router.InitRouter(r)
	//开启pprof 默认路径是debug/pprof
	pprof.Register(r)
	srv.Run(r, config.C.SC.Name, config.C.SC.Addr, nil)
}
